package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.danmo.domain.DanmoCounty;
import com.muyu.danmo.service.IDanmoCountyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 区县信息Controller
 *
 * @author yangle
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/county")
public class DanmoCountyController extends BaseController
{
    @Autowired
    private IDanmoCountyService danmoCountyService;

    /**
     * 查询区县信息列表
     */
//    @RequiresPermissions("system:county:list")
    @GetMapping("/list")
    public Result list(@RequestBody DanmoCounty danmoCounty)
    {
        List<DanmoCounty> list = danmoCountyService.selectDanmoCountyList(danmoCounty);
        return Result.success(list);
    }

    /**
     * 导出区县信息列表
     */
    @RequiresPermissions("system:county:export")
    @Log(title = "区县信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoCounty danmoCounty)
    {
        List<DanmoCounty> list = danmoCountyService.selectDanmoCountyList(danmoCounty);
        ExcelUtil<DanmoCounty> util = new ExcelUtil<DanmoCounty>(DanmoCounty.class);
        util.exportExcel(response, list, "区县信息数据");
    }

    /**
     * 获取区县信息详细信息
     */
//    @RequiresPermissions("system:county:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoCountyService.selectDanmoCountyById(id));
    }

    /**
     * 新增区县信息
     */
//    @RequiresPermissions("system:county:add")
    @Log(title = "区县信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoCounty danmoCounty)
    {
        return toAjax(danmoCountyService.insertDanmoCounty(danmoCounty));
    }

    /**
     * 修改区县信息
     */
//    @RequiresPermissions("system:county:edit")
    @Log(title = "区县信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoCounty danmoCounty)
    {
        return toAjax(danmoCountyService.updateDanmoCounty(danmoCounty));
    }

    /**
     * 删除区县信息
     */
//    @RequiresPermissions("system:county:remove")
    @Log(title = "区县信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoCountyService.deleteDanmoCountyByIds(ids));
    }
}
